﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace QLMBMT
{
    public partial class FrmInPN : DevExpress.XtraEditors.XtraForm
    {
        private SqlDataAdapter da = new SqlDataAdapter();
        private DataSet ds = new DataSet();

        classConnection _classConnection = new classConnection();

        public int STTPN;
       
        public FrmInPN()
        {
            InitializeComponent();
            _classConnection.KetNoiCSDL();
        }

        private void FrmInPN_Load(object sender, EventArgs e)
        {
            rptInPN rpt = new rptInPN();
            DataSetPN dsInPN = new DataSetPN();
            SqlCommand comm = new SqlCommand();
            comm.Connection = _classConnection.con;
            comm.CommandType = CommandType.Text;
            comm.CommandText = "select nh.MAPHIEUNHAP, nh.MAHANG, mh.TENHANG, SOLUONGNHAP, DONGIANHAP,"
                                      + " DONVITINH, THUEVAT, ncc.TENNHACUNGCAP, ncc.DIACHINCC, ncc.SDTNCC, nv.TENNHANVIEN,"
                                       +" (SOLUONGNHAP * DONGIANHAP)+ (SOLUONGNHAP * DONGIANHAP * THUEVAT /100) as THANHTIEN"
                                +" from NHAP_HANG nh"
                                +" left join PHIEU_NHAP pn on nh.MAPHIEUNHAP = pn.MAPHIEUNHAP"
                                +" left join MAT_HANG mh on nh.MAHANG = mh.MAHANG"
                                +" left join NHA_CUNG_CAP ncc on pn.MANHACUNGCAP = ncc.MANHACUNGCAP"
                                +" left join NHAN_VIEN nv on nv.MANHANVIEN = pn.MANHANVIEN"
                                + " where nh.MAPHIEUNHAP = @MAPHIEUNHAP";
            comm.Parameters.Add("MAPHIEUNHAP", SqlDbType.Int).Value = STTPN;
            comm.ExecuteNonQuery();
            da = new SqlDataAdapter();
            da.SelectCommand = comm;
            da.Fill(ds);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                DataRow item = dsInPN.Tables[0].NewRow();
                item["MAPHIEUNHAP"] = dr["MAPHIEUNHAP"];
                item["MAHANG"] = dr["MAHANG"];
                item["TENHANG"] = dr["TENHANG"];
                item["SOLUONGNHAP"] = dr["SOLUONGNHAP"];
                item["DONGIANHAP"] = dr["DONGIANHAP"];
                item["DONVITINH"] = dr["DONVITINH"];
                item["THUEVAT"] = dr["THUEVAT"];
                item["TENNHACUNGCAP"] = dr["TENNHACUNGCAP"];
                item["DIACHINCC"] = dr["DIACHINCC"];
                item["SDTNCC"] = dr["SDTNCC"];
                item["TENNHANVIEN"] = dr["TENNHANVIEN"];
                item["THANHTIEN"] = dr["THANHTIEN"];
                dsInPN.Tables[0].Rows.Add(item);
            }
            rpt.DataSource = dsInPN;
            this.printControl1.PrintingSystem = rpt.PrintingSystem;
            rpt.CreateDocument();
        }
    }
 }
